package com.hanlink.dsp.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.edge.pbxdsp.R;
import com.hanlink.dsp.model.menu.FolderInfo;

import java.util.List;

/**
 * <pre>
 *
 *  BTDSP
 *
 *
 *  Copyright (C): 2015-11-10
 *
 * Description:
 *
 * Revision History
 * Date			  Author		Description
 * 2015-11-10        PeterVon       初始创建
 *
 * </pre>
 */
public class FolderChooseAdapter extends BaseAdapter {

    private Context mContext;
    private List<FolderInfo> mFoldersList;

    public FolderChooseAdapter(Context context, List<FolderInfo> folders) {
        mContext = context;
        mFoldersList = folders;
    }

    @Override
    public int getCount() {
        return mFoldersList == null ? 0 : mFoldersList.size();
    }

    @Override
    public Object getItem(int position) {
        return mFoldersList == null ? null : mFoldersList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {


        FolderHolder holder = null;
        if (convertView == null || !(convertView instanceof LinearLayout)) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.list_item_music, null);
            holder = new FolderHolder(convertView);
        }
        FolderInfo folderInfo = mFoldersList.get(position);
        if (holder != null) {
            holder.txtTitle.setText(folderInfo.getName());
            holder.txtName.setText(folderInfo.getAddr());
        }
        convertView.setTag(folderInfo);
        return convertView;
    }


    class FolderHolder {
        TextView txtTitle;
        TextView txtName;

        public FolderHolder(View view) {
            txtTitle = (TextView) view.findViewById(R.id.txtTitle);
            txtName = (TextView) view.findViewById(R.id.txtName);
        }
    }
}
